<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id ="btn">按钮</button>
    <script>
        var id = "6666"
        var btn = document.getElementById("btn");
        btn.onclick = function(){
            console.log(this.id); //return btn
            setTimeout(function(){
                console.log(this.id); //return 6666  因为这里定时器的实际写法是window.setTimeout(...)
            },100)
            // 解决办法
            setTimeout(function(){
                console.log(this.id);
            }.bind(btn),100)
        }
    </script>
</body>
</html>